Skip to content

Drive util - #18

Merged
zachwaffle4 merged 12 commits into
NextFTC:developfrom
28shettr:DriveUtil
Jul 28, 2026
Merged

Drive util#18
zachwaffle4 merged 12 commits into
NextFTC:developfrom
28shettr:DriveUtil

Conversation

@28shettr

Copy link
Copy Markdown

Mecanum and Tank and technically x drive

data class DriveInput(val x: Double, val y: Double, val rx: Double)

/** Computed power for each wheel of a 4-wheel drivetrain. */
data class WheelPowers(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mecanum and Tank should define their own wheel power classes, because tank should only have two.

)

/** Converts raw drive input into wheel powers for a specific drivetrain type. */
interface DriveKinematics {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should then be generic over the wheel power class, so Mecanum would be MecanumKinematics : DriveKinematics<MecanumWheelPowers>

* used to rotate stick input for field-centric driving. Pass `null` or nothing at all for
* robot-centric driving.
*/
class DrivetrainGroup(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't exist. Just add mecanumDrive and tankDrive as functions that return commands given their kinematics objects + motors, and then field centric variants.

/** Multiplier applied to all stick trigger values. */
var scalar: Double = 1.0
set(value) {
field = value.coerceIn(0.0, 1.0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?


package dev.nextftc.control.drive

data class DriveInput(val x: Double, val y: Double, val rx: Double)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs documentation


data class DriveInput(val x: Double, val y: Double, val rx: Double)

interface DriveKinematics<Output> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs documentation

)

return MecanumWheelPowers(
frontLeft = (input.y + compensatedX + input.rx) / denominator,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you fundamentally misunderstood the coordinate system; +x is forward and +y is left, not the other way around. Thus this should be

Suggested change
frontLeft = (input.y + compensatedX + input.rx) / denominator,
frontLeft = (input.x + compensatedY + input.rx) / denominator,

override fun calculate(input: DriveInput): TankWheelPowers {
val denominator = max(input.y.absoluteValue + input.rx.absoluteValue, 1.0)
return TankWheelPowers(
left = (input.y + input.rx) / denominator,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment about coordinate systems.

* Lightweight wrapper for a distance sensor that caches the last reading.
* Call [update] in periodic to read the hardware.
*
* wait are you able to make new folders and class or nah?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this.

gamepad: Gamepad,
): Command = Commands.infinite {
val powers = kinematics.calculate(
DriveInput(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment about coordinate systems (goes for all of these methods).

@zachwaffle4 zachwaffle4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also merge upstream back into this branch pls

/**
* Lightweight wrapper for a distance sensor that caches the last reading.
* Call [update] in periodic to read the hardware.
*

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a random deletion here that shouldn't be.

* Converts raw drive inputs into tank/differential wheel powers.
*/

class TankKinematics : DriveKinematics<TankWheelPowers> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarify in the documentation that because tank drivetrains aren't holonomic, any y in the DriveInput will be ignored.

@zachwaffle4
zachwaffle4 merged commit d85a08e into NextFTC:develop Jul 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants